import { guid } from '@utility/utility'
// import { getFilePreviewUrl } from '@api/api.js'
import { FILE_PREVIEW_TYPE } from '@utility/dict'

const IMG_TYPES = ['jpeg', 'png', 'jpg']
const VIDEO_TYPES = ['mp4', 'rmp4']
const DOC_TYPES = ['xlsx', 'xls', 'doc', 'docx', 'pdf', 'txt', 'ppt', 'pptx', 'ofd', 'wps']

export function unifyPreviewData(item) {
  if (!item.id) {
    item.id = guid()
  }
  item.fileType = item.fileType.toLowerCase()
  let previewType = ''
  if (IMG_TYPES.includes(item.fileType)) {
    previewType = FILE_PREVIEW_TYPE.img
  } else if (VIDEO_TYPES.includes(item.fileType)) {
    previewType = FILE_PREVIEW_TYPE.video
  } else if (DOC_TYPES.includes(item.fileType)) {
    previewType = FILE_PREVIEW_TYPE.doc
  }
  // const previewPath = getFilePreviewUrl(
  //   (previewType === FILE_PREVIEW_TYPE.doc && item.thumbnailPath) || item.sourcePath
  // )
  return {
    ...item,
    previewType,
    // previewPath
  }
}
